package Demo4;

import java.util.Objects;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86136
 * Date: 2024-05-26
 * Time: 16:07
 */
public class Dog extends Animal implements IRun,ISwimming{

    public Dog(String name, int age) {
        super(name, age);
    }

    @Override
    public void eat() {
        System.out.println(name + "吃狗粮");
    }
    public void bark() {
        System.out.println(name + "汪汪叫");
    }

    @Override
    public void run() {
        System.out.println(name + "在跑");
    }

    @Override
    public void swimming() {
        System.out.println(name + "在游泳");
    }

    @Override
    public boolean equals(Object obj) {
        if(! (obj instanceof Dog) ){
            return false;
        }
        if(obj == null){
            return false;
        }
        /*if(this == obj){
            return true;
        }*/
        Dog tmp = (Dog) obj;
        return this.name.equals(tmp.name)
                && this.age == tmp.age;
    }

    @Override
    //Objects.hash()方法是用于实现有用Object.hashCode()在含有多个字段的对象。
    //hashCode方法必须始终返回相同的整数，前提是修改了对象中equals比较中的信息
    //根据equals(Object)方法两个对象相等，则在两个对象中的每个对象上调用hashCode方法必须产生相同的整数结果。
    public int hashCode() {
        return Objects.hash(name,age);
    }
}
